<template>
    <div>
            <Card>
                <p slot="title">
				    添加车源
			    </p>
                <div>
                    <Form class="step-form" ref="carsourceData" :model="carsourceData" :rules="carsourceDataRules" :label-width="100">
                        <Row span="12">
                            <i-col span="8" >
                                <FormItem prop="brandId" label="品牌名称：" label-position="left" :label-width="150">
                                    <Select @on-change="setBrand" filterable clearable style="width:200px" label-in-value>
                                        <Option v-for="(item,index) in brandList" :value="item.brandId" :key="index" :label="item.brandName">{{ item.brandName }}</Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                            <!--<i-col span="8" >
                                <FormItem prop="seriesId" label="品牌车系：" label-position="left" :label-width="150">
                                    <Select clearable style="width:200px" label-in-value v-model="series_value">
                                        <Option-group v-for="(ite,i) in seriesList" :key="i" :label="ite.subBrand">
                                            <Option  @click.native="setCarSeries1(item)" v-for="(item,index) in ite.carSeries" :value="item.seriesId" :key="index"  :label="item.seriesName">{{ item.seriesName }}</Option>
                                        </Option-group>
                                    </Select>
                                </FormItem>
                            </i-col>-->
                            <i-col span="8" >
                                <FormItem prop="seriesId" label="品牌车系：" label-position="left" :label-width="150">
                                    <Select  filterable clearable style="width:260px" label-in-value>
                                        <Option @click.native="setCarSeries1(item)" v-for="(item,index) in seriesList" :value="item.seriesId" :key="index"  :label="item.seriesName">
                                            <span>{{ item.seriesName }}</span>
                                            <span style="float:right;color:#ccc">{{ item.subBrand }}</span>
                                        </Option>
                                        
                                    </Select>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <!--<i-col span="12" >
                                <FormItem prop="modelId" label="汽车车型：" label-position="left" :label-width="150">
                                    <Select  style="width:340px" v-model="model_value">
                                        <Option-group v-for="(ite,i) in modelsList" :key="i" :label="ite.carYear">
                                            <Option  @click.native="setcarModels(item)" v-for="(item,index) in ite.models" :value="item.modelId" :key="index" :label="item.modelName">{{ item.modelName }}</Option>
                                        </Option-group>
                                    </Select>
                                </FormItem>
                            </i-col>-->
                            <i-col span="12" >
                                <FormItem prop="modelId" label="汽车车型：" label-position="left" :label-width="150">
                                    <Select  filterable clearable style="width:300px" label-in-value>
                                        <Option style="width:420px" @click.native="setcarModels(item)" v-for="(item,index) in modelsList" :value="item.modelId" :key="index"  :label="item.modelName">
                                            <span>{{ item.modelName }}</span>
                                            <span style="float:right;color:#ccc">{{ item.guidancePrice }}</span>
                                        </Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="规格：" prop="" label-position="left" :label-width="150">
                                    <Input :disabled="true" v-model="carsourceData.SPECIFICATION" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="指导价：" prop="" label-position="left" :label-width="150">
                                    <Input :disabled="true" v-model="carsourceData.GUIDANCE_PRICE" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="成交价格：" prop="" label-position="left" :label-width="150">
                                    <Input :disabled="true" v-model="carsourceData.PRICE" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12" v-show="isJKLX == 0">
                            <i-col span="12" >
                                <FormItem label="报价设置：" prop="" label-position="left" :label-width="150">
                                    <Radio-group  v-model="carsourceData.priceType">
                                        <Radio :label="0" :value="0">直接报价</Radio>
                                        <Radio :label="1" :value="1">优惠金额</Radio>
                                        <Radio :label="2" :value="2">优惠点数</Radio>
                                    </Radio-group>
                                     <Input v-model="carsourceData.priceValue" @on-change="setPriceValue" number placeholder="金额不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="定金设置：" prop="EARNEST_PRICE" label-position="left" :label-width="150">
                                    <Input :disabled="false" v-model="carsourceData.EARNEST_PRICE" type="text" placeholder="请输入车源定金（单位：元）" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="车架号后四位：" prop="VIN" label-position="left" :label-width="150">
                                    <Input :disabled="false" v-model="carsourceData.VIN" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="24" >
                                <FormItem label="外观颜色：" prop="OUT_COLOR" label-position="left" :label-width="150">
                                    <Row>
                                        <Radio-group v-model="carsourceData.OUT_COLOR">
                                            <Radio v-for="(item,index) in outColorList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                        </Radio-group>
                                    </Row>
                                    <Row span="12">
                                        <Col span="3">
                                            <Checkbox v-model="location_waiguan">自定义外观颜色</Checkbox>
                                        </Col>
                                        <Col span="7">
                                            <Input :maxlength="15"  :disabled="!location_waiguan" v-model="carsourceData.OUT_COLOR" type="text" placeholder="外观颜色" />
                                        </Col>
                                    </Row>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="24" >
                                <FormItem label="内饰颜色：" prop="IN_COLOR" label-position="left" :label-width="150">
                                    <Row>
                                        <Radio-group v-model="carsourceData.IN_COLOR">
                                                <Radio v-for="(item,index) in inColorList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                            </Radio-group>
                                    </Row>
                                    <Row span="12">
                                        <Col span="3">
                                            <Checkbox v-model="location_neishi">自定义内饰颜色</Checkbox>
                                        </Col>
                                        <Col span="7">
                                            <Input :maxlength="15"  :disabled="!location_neishi" v-model="carsourceData.IN_COLOR" type="text" placeholder="内饰颜色" />
                                        </Col>
                                     </Row>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="期车/现车：" prop="CAR_STATUS" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.CAR_STATUS">
                                        <Radio v-for="(item,index) in carStatus" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="手续情况：" prop="PROCEDURES" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.PROCEDURES">
                                        <Radio v-for="(item,index) in proceduresList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="可售区域：" prop="SELL_AREA" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.SELL_AREA">
                                        <Radio v-for="(item,index) in sellAreaList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="结束时间：" prop="END_TIME" label-position="left" :label-width="150">
                                   <Date-picker  type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期和时间" style="width: 200px" @on-change="carsourceData.END_TIME=$event"></Date-picker>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="14">
                            <i-col span="6" >
                                <FormItem prop="PARTY_ID" label="人员设置：" label-position="left" :label-width="150">
                                    <Select style="width:180px" v-model="carsourceData.PARTY_ID" filterable  label-in-value >
                                        <Option @click.native="setPartyUser(item)" v-for="(item,index) in partys" :value="item.id" :key="index" :label="item.name">{{ item.name }}</Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                            <i-col span="6" >
                                <FormItem prop="USER_ID" label="" label-position="left" :label-width="0">
                                    <Select clearable style="width:200px" v-model="carsourceData.USER_ID" filterable >
                                        <Option v-for="(item,index) in users" :value="item.id" :key="index" :label="item.realName">{{ item.realName }}</Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem prop="" label="车源所在地：" label-position="left" :label-width="150">
                                    <Select style="width:180px" filterable label-in-value >
                                        <Option @click.native="setArea(item)" v-for="(item,index) in areaList" :value="item.cityCode" :key="index" :label="item.cityName">{{ item.cityName }}</Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                            <i-col span="5" >
                                <FormItem prop="" label="" label-position="left" :label-width="0">
                                    <Select clearable style="width:200px"  v-model="carsourceData.CAR_LOCATION" filterable>
                                        <Option v-for="(item,index) in areaCityList" :value="item.cityName" :key="index" :label="item.cityName">{{ item.cityName }}</Option>
                                    </Select>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem prop="CAR_LOCATION" label="车源所在地-自定义：" label-position="left" :label-width="150">
                                    <Checkbox style="margin: 0 auto;" v-model="location_check">
                                    </Checkbox>
                                     <Input  :disabled="!location_check" v-model="carsourceData.CAR_LOCATION" type="text" placeholder="请输入自定义地址" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="经度：" prop="LNG" label-position="left" :label-width="150">
                                    <Input :disabled="false" v-model="carsourceData.LNG" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="纬度：" prop="LAT" label-position="left" :label-width="150">
                                    <Input :disabled="false" v-model="carsourceData.LAT" type="text" placeholder="数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="3">
                                <FormItem label="车源图片：" prop="img_url" label-position="left" :label-width="150">
                                </FormItem>
                            </i-col>
                            <i-col span="20">
                                <template>
                                    <div class="demo-upload-list" v-for="item in uploadList">
                                        <template v-if="item.status === 'finished'">
                                            <img :src="item.url">
                                            <div class="demo-upload-list-cover">
                                                <Icon type="ios-eye-outline" @click.native="handleView(item.url)"></Icon>
                                                <Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
                                            </div>
                                        </template>
                                        <template v-else>
                                            <Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
                                        </template>
                                    </div>
                                    <Upload
                                        ref="upload"
                                        :show-upload-list="false"
                                        :default-file-list="defaultList"
                                        :on-success="handleSuccess"
                                        :format="['jpg','jpeg','png']"
                                        :max-size="2048"
                                        :on-format-error="handleFormatError"
                                        :on-exceeded-size="handleMaxSize"
                                        :before-upload="handleBeforeUpload"
                                        multiple
                                        type="drag"
                                        :data="uploadData"
                                        name="img"
                                        :action="uploadUrl"
                                        style="display: inline-block;width:58px;">
                                        <div style="width: 58px;height:58px;line-height: 58px;">
                                            <Icon type="camera" size="20"></Icon>
                                        </div>
                                    </Upload>
                                    <Modal title="查看图片" v-model="visible">
                                        <img :src="imgViewUrl" v-if="visible" style="width: 100%">
                                    </Modal>
                                </template>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="提车时间：" prop="" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.PICK_TIME">
                                        <Radio v-for="(item,index) in pickTimeList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="票据来源：" prop="" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.INVOICE_SOURCE">
                                        <Radio v-for="(item,index) in invoiceSourceList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="开票方式：" prop="" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.INVOICE_TYPE">
                                        <Radio v-for="(item,index) in invoiceTypeList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="生产日期：" prop="" label-position="left" :label-width="150">
                                   <Radio-group v-model="carsourceData.PRODUCT_TIME">
                                        <Radio v-for="(item,index) in productTimeList" :value="item.value" :key="index" :label="item.value">{{item.value}}</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="备注：" prop="" label-position="left" :label-width="150">
                                   <Input v-model="carsourceData.REMARKS" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入..."></Input>
                                </FormItem>
                            </i-col>
                        </Row>
                        
                        <FormItem >
                            <Button :disabled="hasSubmit" @click="saveData" style="width:100px;" type="primary">提交</Button>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <Button :disabled="hasSubmit" @click="goBack" style="width:100px;" >返回</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
    </div>
</template>

<script>
import ajax from '../../../libs/axios.js'

export default {
    name: 'addUser',
    data () {
        return {
            uploadUrl: ajax.hurl + 'adminlogin/file/uploadOssImage',
            isJKLX:0,//判断是否是进口类型
            defaultList: [],
            imgName: '',
            imgUrl:'',
            imgViewUrl:'',
            visible: false,
            uploadList: [],
            testModelShow: false,
            symptomList:[],
            selectModel:[],
            brandList:[],
            seriesList:[],
            modelsList:[],
            areaList:[],
            areaCityList:[],
            partys:[],
            users:[],
            carStatus:[],
            proceduresList:[],
            sellAreaList:[],
            pickTimeList:[],
            invoiceSourceList:[],
            invoiceTypeList:[],
            productTimeList:[],
            outColorList:[],
            inColorList:[],
            location_check:false,
            location_waiguan:false,
            location_neishi:false,
            series_value:'',
            model_value:'',
            carsourceData: {
                brandId:'',
                brandValue:'',
                seriesValue:'',
                seriesId:'',
                modelValue:'',
                modelId:'',
                imgs:[],
                BRAND:'',//品牌
                SERIES:'',//车系
                MODEL:'',//车型
                MODEL_ID:'',//车型Id
                CAR_YEAR:'',//年款
                PL:'',
                OUT_COLOR:'',//外观颜色
                IN_COLOR:'',//内饰颜色
                SPECIFICATION:'',//规格
                CAR_LOCATION:'',//车源所在地
                GUIDANCE_PRICE:'',//指导价
                EARNEST_PRICE:'',//车辆定金
                PRICE:0,//成交价
                DISCOUNT_AMT:0,//优惠金额
                ADD_AMT:0,//加价金额
                ADD_POINT:0,//加价点数
                DISCOUNT_POINT:0,//优惠点数
                VIN:'',//车架号后四位
                CAR_STATUS:'',// 期车/现车
                PROCEDURES:'',//手续
                SELL_AREA:'',//销售区域
                PICK_TIME:'',//提车时间
                PICK_TIME:'',//提车时间
                PARTY_ID:'',//企业id
                PARTY_NAME:'',//企业名称
                USER_ID:'',//用户id
                STATUS:0,//车源状态
                TYPE:'1',//数据来源
                INVOICE_SOURCE:'',//票据来源
                INVOICE_TYPE:'',//开票方式
                PRODUCT_TIME:'',//生产日期
                REMARKS:'',//备注
                END_TIME:'',//有效期结束时间
                LNG:'0',//经度
                LAT:'0',//纬度
                OPERATOR:'',//操作者
                priceType:0,
                priceValue:0,
                img_link:'',//车源所在地
                skip_type:1,
                is_enable:0,
                img_url: '',
                num:1,
                type:1
            },
            carsourceDataRules: {
                brandId: [
                    { required: true, message: '品牌不能设置为空', trigger: 'blur'}
                ],
                seriesId: [
                    { required: true, message: '车系不能设置为空', trigger: 'blur'}
                ],
                modelId: [
                    { required: true, message: '车型不能设置为空', trigger: 'blur'}
                ],
                PRICE: [
                    { required: true, message: '成交价格不能为空', trigger: 'blur'}
                ],
                EARNEST_PRICE: [
                    { required: true, message: '车辆定金不能为空', trigger: 'blur'}
                ],
                VIN: [
                    { required: true, message: '车架号不能为空', trigger: 'blur'},
                    {type: 'string', max: 4, message: '不能超过4个字符', trigger: 'blur'}
                ],
                OUT_COLOR:[
                    { required: true, message: '请选择外观颜色', trigger: 'blur'}
                ],
                IN_COLOR:[
                    { required: true, message: '请选择内饰颜色', trigger: 'blur'}
                ],
                CAR_STATUS:[
                    { required: true, message: '规格不能设置为空', trigger: 'blur'}
                ],
                PARTY_ID:[
                    { required: true, message: '4s店不能设置为空', trigger: 'blur'}
                ],
                USER_ID:[
                    { required: true, message: '人员不能设置为空', trigger: 'blur'}
                ],
                CAR_LOCATION:[
                    { required: true, message: '所在地不能设置为空', trigger: 'blur'}
                ],
                PROCEDURES:[
                    { required: true, message: '请设置手续情况', trigger: 'blur'}
                ],
                SELL_AREA:[
                    { required: true, message: '请设置可售区域', trigger: 'blur'}
                ],
                priceValue:[
                   // { required: true, message: '数据不能为空', trigger: 'blur'}
                   // { message: '最小分只能是数字', trigger:'change', pattern:/^(([1-9]\d{0,3})|0)(\.\d{0,2})?$/,}
                ],
                END_TIME:[
                    { required: true, message: '请设置结束时间', trigger: 'blur'}
                ]
                // 暂时不进行验证
                // imgUrl: [
                //     { required: true, message: '请上传疾病图片', trigger: 'blur'},
                // ]
                
            },
            hasSubmit: false,
            // 图片上传
            file: null,
            status: 'wait',
            uploadData: {
                        type: 'carSource'
                    }
        }
    },
    methods: {
        // 数据初始化
        init () {
            this.carsourceData.OPERATOR = window.localStorage.getItem('userId')
            this.$store.commit('setActiveName', 'carsourceindex');
            this.getCarBrands();
            this.selectBaseInfos();
        },
        handleView (url) {
                this.imgViewUrl = url;
                this.visible = true;
            },
            handleRemove (file) {
                // 从 upload 实例删除数据
                const fileList = this.$refs.upload.fileList;
                this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
            },
            handleSuccess (res, file) {
                // 因为上传过程为实例，这里模拟添加 url
                
                this.upload(res)

                file.url = this.imgUrl;
                file.name = this.imgName;
            },
            handleFormatError (file) {
                this.$Notice.warning({
                    title: '文件格式不正确',
                    desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
                });
            },
            handleMaxSize (file) {
                this.$Notice.warning({
                    title: '超出文件大小限制',
                    desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
                });
            },
            handleBeforeUpload (file) {
                const check = this.uploadList.length < 9;
                if (!check) {
                    this.$Notice.warning({
                        title: '最多只能上传 9 张图片。'
                    });
                }else{
                    this.uploadType = 1
                    this.file = file
                }
                return check;
            },
        // 上传图片
        upload (res) {
            let that = this
            let fileName = that.file.name
            //FormData 对象
            // let formData = new FormData()
            console.log(fileName)
            this.uploadLoading = true
            // 文件对象
            // formData.append("img", that.file)
            // formData.append("type", "carSource")
            // ajax.upload('adminlogin/file/uploadOssImage',formData).then(function (res) {
                that.imgUrl = res.url
                that.imgName = res.name
                that.file = ''
                that.$Message.success('上传成功')              
                //that.uploadLoading = false
            // }, function (err) {
            //     console.log(err)
            //     //this.uploadLoading = false
            // }).catch(function (error) {
            //     console.log(error)
            //     //this.uploadLoading = false
            // })
        },
        setBrand(obj){
            this.carsourceData.brandId=obj.value;
            this.carsourceData.brandValue=obj.label;
            this.carsourceData.BRAND=obj.label;
            this.series_value = '';
            this.model_value = '';
            this.getCarSeries(obj.value);
            
        },
        setCarSeries1(obj){//设置车系
            this.carsourceData.seriesId=obj.seriesId;
            this.carsourceData.seriesValue=obj.seriesName;
            this.carsourceData.SERIES = obj.seriesName;
            debugger
            obj.subBrand.indexOf("平行进口") >=0 ? this.isJKLX=1:this.isJKLX=0;
            this.model_value = '';
            this.getCarModels(obj.seriesId);
            
        },
        setPriceValue(value){//设置金额
            // console.log("***********************",this.carsourceData.priceValue)
            // console.log("*************类型**********",this.carsourceData.priceType)
            // console.log("*************是否是数据**********",typeof this.carsourceData.priceValue === 'number' && !isNaN(this.carsourceData.priceValue))
            // ;
            let pValue = this.carsourceData.priceValue;
            if(typeof pValue === 'number' && !isNaN(pValue)){
                if(this.carsourceData.priceType == 0){
                    this.carsourceData.PRICE = pValue
                }else if(this.carsourceData.priceType == 1){
                    if(pValue>0){
                        this.carsourceData.DISCOUNT_AMT = pValue;
                    }else{
                        this.carsourceData.ADD_AMT = pValue;
                    }
                    this.carsourceData.PRICE = (this.carsourceData.GUIDANCE_PRICE - pValue).toFixed(2);
                }else if(this.carsourceData.priceType == 2){
                    if(pValue>=0){
                        this.carsourceData.DISCOUNT_POINT = pValue;
                    }else{
                        this.carsourceData.ADD_POINT = pValue;
                    }
                    this.carsourceData.PRICE = (this.carsourceData.GUIDANCE_PRICE - this.carsourceData.GUIDANCE_PRICE*pValue/100).toFixed(2);
                }
            }else{
                this.carsourceData.priceValue = 0;
                this.$Notice.warning({
                    title: '请输入数字格式的数据。'
                });
            }
        },
        setcarModels(item){
            this.carsourceData.modelId = item.modelId;
            this.carsourceData.modelValue = item.modelName;
            this.carsourceData.MODEL=item.modelName;
            this.carsourceData.MODEL_ID=item.modelId;
            this.carsourceData.CAR_YEAR=item.carYear;
            this.carsourceData.PL=item.pl;
            this.carsourceData.SPECIFICATION = item.jklx;
            this.carsourceData.GUIDANCE_PRICE = item.guidancePrice;
            this.carsourceData.PRICE = item.guidancePrice;
            this.carsourceData.priceValue = item.guidancePrice;
            
        },
        getCarModels(seriesId){
            let _that = this;
            let url = '/adminlogin/car/getCarModelsBySeriesId'
            let data = {
                seriesId:seriesId
            }
            ajax.formRes(url, data).then(res => {
                _that.modelsList = res.data;
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
            
            
        },
        getCarSeries(brandId){
            let _that = this
            _that.seriesList = []
            let url = '/adminlogin/car/getCarSeriesByBrandId'
            let data = {
                brandId:brandId
            }
            ajax.formRes(url, data).then(res => {
                debugger
                _that.seriesList = res.data
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        getCarBrands(){
            let _that = this;
            let url = '/adminlogin/car/getCarBrands'
            let data = {
            }
            ajax.formRes(url, data).then(res => {
                _that.brandList = res.data;
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        selectBaseInfos(){//获取区域信息
            let _that = this;
            let url = '/adminlogin/carsource/selectBaseInfos'
            let data = {
            }
            ajax.formRes(url, data).then(res => {
                _that.partys = res.partys;
                _that.areaList = res.area;
                _that.carStatus=res.carStatus;
                _that.proceduresList=res.procedures;
                _that.sellAreaList = res.sellArea;
                _that.pickTimeList = res.pickTime;
                _that.invoiceSourceList = res.invoiceSource;
                _that.invoiceTypeList=res.invoiceType;
                _that.productTimeList=res.productTime;
                _that.outColorList=res.outColor;
                _that.inColorList=res.inColor;
            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        setArea(obj){
            this.areaCityList = obj.citys;
        },
        setPartyUser(obj){
            this.carsourceData.PARTY_ID = obj.id;
            this.carsourceData.PARTY_NAME = obj.name;
            this.carsourceData.USER_ID = '';
            this.users = obj.users;
        },
        
        // 添加数据
        saveData () {
            
            let that = this
            let file = this.$refs.upload.fileList;
            this.carsourceData.imgs = JSON.stringify(file);
            that.$refs['carsourceData'].validate((valid) => {
                if (valid) {
                    that.hasSubmit = true
                    let url = 'adminlogin/carsource/addInfo'
                    let data = that.carsourceData
                    ajax.formRes(url, data).then(res => {
                        // success
                        that.$Message.success('新增数据成功,页面正在跳转')
                        that.hasSubmit = false
                            let argu = {
                            }
                            that.$router.push({
                                name: 'carsourceindex',
                                params: argu
                            })
                    }).catch(res => {
                        console.log('有错误信息')
                        // fail
                    })
                } else {
                    console.log('新增失败。。。')
                }
            })
        },
        goBack () {
            this.$router.push({
                name: 'carsourceindex'
            })
        },
        // 症状
        hideModel (value) {
            this.testModelShow = false
        },
        addSymptom () {
            // 点击不同按钮传不同的值，此处重新重新回显被选中的值加载网络不好的情况反应会很慢需要加载菊花
            this.$refs.symptomModel.init()
            this.selectModel = this.symptomList
            this.testModelShow = true
        }
        
    },
    mounted () {
        this.uploadList = this.$refs.upload.fileList;
    },
    created: function () {
        this.init()
    },
    activated: function () {
        this.init()
    }
}
</script>
<style>
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .card-upload:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }
    .demo-upload-list{
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0,0,0,.2);
        margin-right: 4px;
    }
    .demo-upload-list img{
        width: 100%;
        height: 100%;
    }
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .demo-upload-list:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
</style>

